home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 15397 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.8 KB  |  54 lines

  1. Path: netnews.NCTU.edu.tw!usenet
  2. From: ben@water.ee.nsysu.edu.tw (Benjamin Han)
  3. Newsgroups: comp.lang.c++
  4. Subject: CodeGuard: alarm producer or what?
  5. Date: Fri, 05 Apr 1996 03:44:13 GMT
  6. Organization: AI lab, dept. of E.E., NSYSU.
  7. Message-ID: <31648ded.5066048@netnews.nctu.edu.tw>
  8. Reply-To: ben@water.ee.nsysu.edu.tw
  9. NNTP-Posting-Host: ben.ee.nsysu.edu.tw
  10. X-Newsreader: Forte Agent .99d/32.182
  11.  
  12. Yesterday I tried to rebuild my project with CodeGuard 1.0 for Borland C++ 4.53
  13. -- just to make sure that no nasty bugs in it any more. It's basically a console
  14. program accepting an argument so that you can specify the target file you want
  15. it to deal with. After building, I ran once with a legal file name, and all went
  16. fine (no alarms, thanks God). Then I deliberately missed the first argument, so
  17. that the exception throw-and-catch code somewhere in my project could be
  18. triggered. Guess what? A more-than-500-line errors report was thrown on me. I
  19. checked the report, and found some destructors were not executed at all before
  20. the program was terminated. However, I was still not quite sure (Borland is a
  21. big name, isn't it?) , so I wrote a simple testing code (shown below) and tested
  22. it,
  23.  
  24. =============================================================
  25. class Foo
  26. {
  27.   char *buffer;
  28.  
  29.   public:
  30.  
  31.   Foo (): buffer(new char[100]) {}
  32.   ~Foo () { delete[] buffer; }
  33. };
  34.  
  35.  
  36. void main (void)
  37. {
  38.   Foo foo;
  39.  
  40.   throw;
  41. }
  42. =============================================================
  43.  
  44. the result: an error report with more than 70 lines. All were complaints about
  45. 'memory leak' of some blockes allocated by function 'malloc'! When I commented
  46. out  the throw statement, everything was back to normal. Now I'm confused --
  47. could anybody out there explain this to me? Thanks in advance.
  48.  
  49.  
  50. Benjamin Han
  51. AI lab, Dept. of E.E.,
  52. National Sun Yat-sen Univ.,
  53. Taiwan, ROC.
  54.